-
Notifications
You must be signed in to change notification settings - Fork 98
refactor: Centralize error output #3902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
… link between GEOS_THROW_CTX_IF and LVARRAY_THROW_IF_TEST( EXP, MSG, TYPE )
… in try/catch statements Problem: Retrieves everything that was thrown, so not just the message.
…/catch in main)": remove useless try/catch
…y spaces. The previous condition checked whether an argument was present and whether the option was immediately followed by a value like -test"value", which excluded valid cases like -test "value" et -test "value".
src/main/main.cpp
Outdated
| } | ||
| catch( std::exception const & e ) | ||
| { // native exceptions management | ||
| ErrorLogger::ErrorMsg & errMsg = ErrorLogger::global().currentErrorMsg(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it lacks a lot of information here: at this point, IIRC, GEOS_THOW() has never been called, so the same information must be provided to the error message.
Appart from that, this part is a lot better!
| * potencially at various application layers | ||
| * Use flushErrorMsg() when the message is fully constructed and you want it to be output | ||
| * @return Reference to the current instance for method chaining. | ||
| * potencially at various application layers (Typically for exceptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Typically for exceptions"
Are there other use-cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have now 2 flush methods
| ErrorContext( map< Attribute, std::string > attributes, integer priority ): | ||
| m_dataDisplayString( "" ), | ||
| m_attributes( attributes ), | ||
| m_priority( priority ) {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_dataDisplayString is allowed as empty? Isn't that the source of your issue in the unit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what is needed : ErrorContext( string formattedContext, map< Attribute, std::string > attributes, integer priority ):
| ErrorLogger::global().beginLogger() | ||
| .addSignalToMsg( signal ) | ||
| .setType( ErrorLogger::MsgType::Error ) | ||
| .addRank( ::geos::logger::internal::g_rank ) | ||
| .addCallStackInfo( stackHistory ) | ||
| .addContextInfo( | ||
| ErrorContext{ { { ErrorContext::Attribute::Signal, std::to_string( signal ) } }, 1 }, | ||
| ErrorContext{ { { ErrorContext::Attribute::DetectionLoc, string( "signal handler" ) } }, 0 } ) | ||
| .flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a unit test for signals would be a good thing.
| "***** - {}\n", | ||
| testErrorLogger.getCurrentExceptionMsg().m_file, line1, | ||
| testErrorLogger.getCurrentExceptionMsg().m_cause, | ||
| context.toString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you switch with the most important context here?
| /// Error message logger for structured error reporting | ||
| DiagnosticMsg m_errorMsg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't that in currentExceptionMsg()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
| void prepareWhat( std::string const & msg, | ||
| std::string const & cause, | ||
| char const * file, | ||
| int line, | ||
| int rank, | ||
| string_view stackTrace ) noexcept | ||
| { | ||
| try | ||
| { | ||
| std::ostringstream oss; | ||
| oss << "***** GEOS Exception\n"; | ||
| oss << "***** LOCATION: " << file << ":" << line << "\n"; | ||
| oss << "***** " << cause << "\n"; | ||
| oss << "***** Rank " << rank << ": "<< msg <<"\n\n"; | ||
| oss << stackTrace; | ||
| m_cachedWhat = oss.str(); | ||
| } catch( ... ) | ||
| { | ||
| m_cachedWhat = "GEOS Exception (formatting failed)"; | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| void prepareWhat( std::string const & msg, | |
| std::string const & cause, | |
| char const * file, | |
| int line, | |
| int rank, | |
| string_view stackTrace ) noexcept | |
| { | |
| try | |
| { | |
| std::ostringstream oss; | |
| oss << "***** GEOS Exception\n"; | |
| oss << "***** LOCATION: " << file << ":" << line << "\n"; | |
| oss << "***** " << cause << "\n"; | |
| oss << "***** Rank " << rank << ": "<< msg <<"\n\n"; | |
| oss << stackTrace; | |
| m_cachedWhat = oss.str(); | |
| } catch( ... ) | |
| { | |
| m_cachedWhat = "GEOS Exception (formatting failed)"; | |
| } | |
| } | |
| private: | |
| static thread_local std::ostringstream formattingOSS; | |
| public: | |
| void prepareWhat( ErrorMsg const & msg ) noexcept | |
| { | |
| formattingOSS.str(""); | |
| formattingOSS.clear(); | |
| ErrorLogger::writeToAscii( msg, formattingOSS ); | |
| m_cachedWhat = formattingOSS.bad ? "Exception formatting error!" : formattingOSS.str(); | |
| m_errorMsg = msg; | |
| } |
| .addToMsg( e.what() ) | ||
| .addRank( ::geos::logger::internal::g_rank ) | ||
| .addCallStackInfo( LvArray::system::stackTrace( true ) ) | ||
| .get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who get what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
| /// The diagnosticMsg being constructed | ||
| DiagnosticMsg m_errorMsg; | ||
| /// The target diagnosticMsg | ||
| DiagnosticMsg * m_targetErrorMsg = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// The diagnosticMsg being constructed | |
| DiagnosticMsg m_errorMsg; | |
| /// The target diagnosticMsg | |
| DiagnosticMsg * m_targetErrorMsg = nullptr; | |
| /// The target diagnosticMsg | |
| DiagnosticMsg & m_targetErrorMsg; |
| ErrorContext( map< Attribute, std::string > attributes, integer priority ): | ||
| m_dataDisplayString( "" ), | ||
| m_attributes( attributes ), | ||
| m_priority( priority ) {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what is needed : ErrorContext( string formattedContext, map< Attribute, std::string > attributes, integer priority ):
|
|
||
| /** | ||
| * @brief Write all the information retrieved about the error/warning message into the YAML file | ||
| * @param errorMsg a constant reference to the error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not const
| void flushCurrentExceptionMessage(); | ||
|
|
||
| /** | ||
| * @brief Write all the information retrieved about the diagnostic message into the instance | ||
| * outputs (stream specified + optional yaml file) | ||
| * @param errorMsg a reference to the ErrorMsg to output, and will be re-initialized | ||
| * @note Used for warnings and non-exception errors | ||
| */ | ||
| void flushErrorMsg( DiagnosticMsg & errMsg ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provide a oss parameter (with a default to std::cout)?
| static DiagnosticMsgBuilder init() | ||
| { return DiagnosticMsgBuilder();} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static ErrorMsgBuilder init( ErrorMsg & msg,
MsgType msgType,
std::string_view msgContent,
integer rank,
std::string_view msgFile,
integer msgLine );
What do you think of this suggestion? ^
Is that too constraining?
(internally, that would call the builder methods)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for init with parameters but I removed file & line. For the signal we don't have file & line
Remove code duplication found in
GEOS_THROW,GEOS_ERROR,GEOS_WARNINGand put into a static function inErrorLogger.Called while
flushErrorMsg().Move all Exceptions under GeosExceptions.hpp